using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
	[DataObject(true)]
    public partial class CategoryController
    {
	
		public SqlDataProvider DataProvider { get; set; }

        public CategoryController()
        {
            DataProvider = new SqlDataProvider();
        }
	
		[DataObjectMethod(DataObjectMethodType.Insert, true)]
        public Guid InsertCategory(CategoryInfo oi)
		{
            return DataProvider.InsertCategory(oi.Name);
		}

		[DataObjectMethod(DataObjectMethodType.Update, true)]
        public int UpdateCategory(CategoryInfo oi) 
		{
			return DataProvider.UpdateCategory(oi.CategoryId, oi.Name);
		}
		
		[DataObjectMethod(DataObjectMethodType.Delete, true)]
        public int DeleteCategory(Guid categoryId)
		{
			return DataProvider.DeleteCategory(categoryId);
        }

		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public CategoryInfo SelectCategory(Guid categoryId)
        {    
			return ObjectFromDataRow(DataProvider.SelectCategory(categoryId));
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<CategoryInfo> SelectCategories()
		{
            return ListFromDataTable(DataProvider.SelectCategories());
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<CategoryInfo> SelectCategories(string sortExpression)
        {
            List<CategoryInfo> retList = SelectCategories();
            if (sortExpression.Length > 0)
            {
                retList.Sort(new CategoryComparer(sortExpression));
            }
            return retList;
        }

	}

}
		